<%@page import="com.muk.meis.model.bean.UserProfile"%>
<%@page import="com.muk.meis.MEISConstance"%>
<%@page import="com.muk.meis.model.bean.SchoolNew"%>
<%@page import="com.muk.meis.model.service.SchoolNewsService"%>
<%@page import="com.muk.meis.model.bean.SchoolInfo"%>
<%@page import="com.muk.meis.model.service.SchoolInfoService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MEIS</title>
<link href="layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../js/flot/excanvas.min.js"></script><![endif]-->
<link href="../css/dropdown/themes/default/helper.css" media="screen"
	rel="stylesheet" type="text/css" />
<link type="text/css" href="../css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<link type="text/css" href="../css/meis.css" rel="stylesheet" />	
<!-- Beginning of compulsory code below -->

<link href="../css/dropdown/dropdown.css" media="screen"
	rel="stylesheet" type="text/css" />
<link href="../css/dropdown/themes/default/default.css" media="screen"
	rel="stylesheet" type="text/css" />

<!--[if lt IE 7]>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jquery/jquery.dropdown.js"></script>
<![endif]-->

<!-- / END -->
<script language="javascript" type="text/javascript"
	src="../js/flot/jquery.flot.js"></script>
<style type="text/css">
.mesi_header_m {
	color: #F00;
}
</style>
</head>
<body>
		<%
		String newsId = request.getParameter("newsid");
		String perCode = request.getParameter("percode");
		SchoolNewsService service = new SchoolNewsService();
		SchoolNew news = service.getDetail(Integer.parseInt(newsId));
		boolean isEdit = false;
		UserProfile userPassLogin = (UserProfile)session.getAttribute(MEISConstance.USER_PASS_LOGIN);
		if((userPassLogin != null) &&
		   ((news.getUserId() == userPassLogin.getUserId())||MEISConstance.ADMIN_ROLE.equals(userPassLogin.getRole())) &&
		   (MEISConstance.ADMIN_ROLE.equals(userPassLogin.getRole())||
		    perCode.equals(userPassLogin.getPercodeCode()))){
			  isEdit = true;	  
		}
		%>
	<form action="<%=request.getContextPath()+"/NewsController/update"%>">
		<% if(userPassLogin !=null) { %>
          <jsp:include page="../menu_admin.jsp"></jsp:include>
	    <%} else { %>
	       <div style="position:relative;background-image: url('../image/header_background.gif'); width:1000px; height:140px; color: #333;font-size:25px;">
	          <div style="width:800px; padding-left:50px;padding-top:50px;"><span class="mesi_header_m">M</span>ukdahan education information system</div>
	       </div>
	    <%} %>
		<div style="position: relative; padding-top: 60px; padding-left: 150px;">
		<input type="hidden" name="newsid" value="<%=newsId%>"/>
		<input type="hidden" name=percode value="<%=perCode%>"/>
		<%if(!isEdit) {%>
			<img alt="" src="../image/button_back.jpg" style="width: 30px;cursor: pointer;" onclick="javascript:history.back();"/>
		<% }%>
			<table style="position: relative;padding-top: 15px;">
				<tr>
					<td>หัวข้อข่าว</td>
					<% if(isEdit) { %>
					    <td><input type="text" size="60" name="title" value="<%=news.getTitle()%>" />
					<%} else { %>
					    <td>:<%=news.getTitle() %></td>
					<%} %>
					</td>
				</tr>
				<tr>
					<td>ข้อความ</td>
					<% if(isEdit) { %>
					    <td><textarea rows="5" cols="50" name="message"><%=news.getMessage()%></textarea>
					<%} else { %>
					    <td>:<%=news.getMessage()%></td>
					<%} %>
					</td>
				</tr>
			</table>
			<% if(isEdit) { %>
			    <input type="submit" name="save" value="บันทึก" />
			<%} %>
		</div>
	</form>
</body>
</html>